<?php

$res = json_decode(file_get_contents('php://input'), true);

$session = $res['session'];

$url = "http://211.82.48.36/student/teachingResources/gradeAndClassCurriculum/subjectJson?departmentNum=" . $res['value'];
// $url = "http://211.82.48.36/student/teachingResources/gradeAndClassCurriculum/subjectJson?departmentNum=09";
$curl = curl_init();

//$session = 'JSESSIONID=abceFLKVAYqkyahOLeTbx';

curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_COOKIE, $session);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36";
curl_setopt($curl, CURLOPT_USERAGENT, $user_agent);
curl_setopt($curl, CURLOPT_ACCEPT_ENCODING, "gzip,deflate");
// $proxy = "127.0.0.1:2333";
// curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
// curl_setopt($curl, CURLOPT_PROXY, $proxy);

$result = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
// curl_close($curl);


if ($httpCode != 200) {
    $arr = array('err' => 1);
    exit(json_encode($arr));
}

$content = json_decode($result, true);


$result_arr_0 = [];
$result_arr_1 = [];


$result_arr_0[] = "未选择";
$result_arr_1[] = 0;
if (is_array($content)) {
    foreach ($content as $value0) {
        $name = $value0['subjectName']; //专业名
        $code = $value0['subjectCode']; //专业号
        $result_arr_0[] = $name;
        $result_arr_1[] = $code;
    }
}


$result_arr = array($result_arr_0, $result_arr_1);

$arr = array('err' => 0, 'major' =>  $result_arr_0, 'major_id' =>  $result_arr_1, 'curl_getinfo' => curl_getinfo($curl), 'httpCode' => $httpCode, 'url' => $url);
exit(json_encode($arr));
